using System;
using System.Data;
using System.Data.SqlClient;
 

/// <summary>
/// Summary description for JobSeeker
/// </summary>
public partial class SqlServerProvider
{


    public bool DeleteSavedSearch(string userID, string searchID)
    {
        bool deleteItem = false;
        errorMessage = "";
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPDeleteSavedSearch";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue(
            "@UserID", userID);
            sqlCommand.Parameters.AddWithValue(
            "@SearchID", searchID);
            deleteItem = (sqlCommand.ExecuteNonQuery() > 0);
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return deleteItem;
    }
    public bool DeleteAppliedJob(string resumeID, string jobID)
    {
        bool deleteItem = false;
        errorMessage = "";
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPDeleteAppliedJob";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue(
            "@ResumeID ", resumeID);
            sqlCommand.Parameters.AddWithValue(
            "@JobID", jobID);
            deleteItem = (sqlCommand.ExecuteNonQuery() > 0);
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return deleteItem;
    }
    public bool DeleteSavedJob(string userID, string jobID)    
    {
        bool deleteItem = false;
        errorMessage = "";
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPDeleteSavedJob";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue(
            "@UserID", userID);
            sqlCommand.Parameters.AddWithValue(
            "@JobID", jobID);           
            deleteItem = (sqlCommand.ExecuteNonQuery() > 0);
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return deleteItem;
    }
    public bool SaveJobSearch(string userID, string keyWord, string cityName, string jobCategory, string jobIndustry)
    {
        bool saveJobSearch = false;
        errorMessage = "";
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPSaveSearch";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue(
            "@UserID", userID);
            sqlCommand.Parameters.AddWithValue(
            "@KeyWord", keyWord);
            sqlCommand.Parameters.AddWithValue(
            "@CityName", cityName);
            sqlCommand.Parameters.AddWithValue(
           "@JobCategory", jobCategory);
            sqlCommand.Parameters.AddWithValue(
            "@JobIndustry", jobIndustry);
            saveJobSearch = (sqlCommand.ExecuteNonQuery() > 0);
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return saveJobSearch;
    }

    public bool SaveJob(string userID, string jobID)
    {
        bool saveJob = false;
        errorMessage = "";
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPSaveJob";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue(
            "@UserID", userID);
            sqlCommand.Parameters.AddWithValue(
            "@JobID", jobID);
             
            saveJob = (sqlCommand.ExecuteNonQuery() > 0);
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return saveJob;
    }
    
    public bool ApplyJob(int jsResumeID, int jobID)
	 {
	    bool saveApply = false;
        errorMessage = "";       
        try
        {
            OpenConnection();
            sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "SPJobApply";
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandType =
            CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue(
            "@JobID", jobID );
            sqlCommand.Parameters.AddWithValue(
            "@ResumeID", jsResumeID);            
            saveApply = (sqlCommand.ExecuteNonQuery()>0);             
            CloseConnection();
        }
        catch (SqlException sql)
        {
            errorCode = sql.Number;
            errorMessage = sql.Message;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return saveApply;
	    
	 }
}
